import simpleGit, { SimpleGitOptions } from 'simple-git'
import createLogger from 'progress-estimator'
import chalk from 'chalk'


// 初始化进度条
const logger = createLogger({
    spinner: {
        interval: 100,
        frames: ['#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'].map((item) => {
            chalk.green(item)
            return item
        }),
    }
})

const getOptions: Partial<SimpleGitOptions> = {
    baseDir: process.cwd(), // 当前工作目录
    binary: 'git', // git 二进制文件路径
    maxConcurrentProcesses: 6, // 允许同时进行的最大进程数
};
export const clone = async (url: string, projectName: string, options: string[]) => {
    const git = simpleGit(getOptions);
    try {
        await logger(git.clone(url, projectName, options), 'loading...', {
            estimate: 7000 // 预计耗时
        })
        console.log(chalk.green(`${projectName} create success`));
        console.log(chalk.blackBright('==============================================================='))
        console.log(chalk.blackBright('==============Welcome to the use of scaffolding================'))
        console.log(chalk.blackBright('==============================================================='))
        console.log(chalk.blackBright('===============Use the NPM installation dependency============='))
        console.log(chalk.blackBright('=============To work with NPM RUN DEV startup project=========='))
    } catch (err) {
        console.log(chalk.red(`${projectName} create fail`))
        console.log(err)
    }
}